export default {
  /**
   * 重新播放
   */
  onReplay() {
    if (!this.isLoading) {
      this.onDestroy().then(() => {
        this.playCreate();
        console.log(this.playerInfo);
        this.onPlayer();
      });
    }
  },
  /**
   * 销毁播放器
   */
  onDestroy() {
    return new Promise((resolve) => {
      console.log(this.playerInfo);
      if (this.playerInfo) {
        this.playerInfo.destroy();
        this.playerInfo = null;
      }
      setTimeout(resolve, 100);
    });
  },
  /**
   * 播放直播
   */
  onPlayerPlayback() {
    this.onDestroy().then(() => {
      this.playCreate();
      this.config.isLive = false;
      setTimeout(() => {
        if (this.playerInfo) {
          this.playerInfo
            .play(this.videoObject.src)
            .then(() => {
              this.isLoading = false;
            })
            .catch((e) => {
              console.error(e);
              this.isLoading = false;
            });
        } else {
          console.error('Player info is not initialized');
          this.isLoading = false;
        }
      }, 0);
    });
  },
  /**
   * 停止
   */
  onStop() {
    this.isPlay = false;
    this.onDestroy().then(() => {
      this.playCreate();
    });
  },
  /**
   * 播放类型切换
   */
  onUse(type) {
    if (type === 'hasAudio') {
      this.config.hasAudio = !this.config.hasAudio;
    } else {
      this.config.MSE = false;
      this.config.WCS = false;
      if (type === 'MSE') this.config.MSE = true;
      if (type === 'WCS') this.config.WCS = true;
    }
    if (this.isPlay) {
      this.onDestroy().then(() => {
        this.playCreate();
        this.onPlayer();
      });
    }
  },
  /**
   * 全屏
   */
  setFullscreen() {
    this.playerInfo.setFullscreen(true);
  },
  /**
   * 暂停
   */
  onPause() {
    this.playerInfo.pause();
  },
  /**
   * 静音
   */
  onMute() {
    this.playerInfo.setMute(true);
  },
};
